package com.vv.vv_commonlibrary.listener;

import android.view.View;

/**
 * RecycleView 长按点击事件
 *
 * @author xia
 */
public class RecycleItemLongClickListener<T> implements View.OnLongClickListener {

    /**
     * RecycleView内部的RecycleViewItem的点击时间的回调
     */
    private OnRecycleViewItemLongClickListener onRecycleViewItemLongClickListener;
    /**
     * 点击的序号
     */
    private int position;
    /**
     * 点击的Item的对象
     */
    private T entity;

    public void setPosition(int position) {
        this.position = position;
    }

    public void setEntity(T entity) {
        this.entity = entity;
    }

    public RecycleItemLongClickListener(OnRecycleViewItemLongClickListener onRecycleViewItemLongClickListener) {
        this.onRecycleViewItemLongClickListener = onRecycleViewItemLongClickListener;
    }

    public RecycleItemLongClickListener(OnRecycleViewItemLongClickListener onRecycleViewItemLongClickListener, int position, T entity) {
        this.onRecycleViewItemLongClickListener = onRecycleViewItemLongClickListener;
        this.position = position;
        this.entity = entity;
    }

    @Override
    public boolean onLongClick(View v) {
        if (onRecycleViewItemLongClickListener != null) {
            onRecycleViewItemLongClickListener.onRecycleViewItemLongClick(v, entity, position);
        }
        return false;
    }

    public interface OnRecycleViewItemLongClickListener<T> {

        /**
         * 用于处理RecycleView的Item的内部View的点击事件的回调
         *
         * @param itemView RecycleView里面点击的对象
         * @param entity   点击对象对应的item返回的实体类
         * @param position RecycleView的序号
         */
        void onRecycleViewItemLongClick(View itemView, T entity, int position);

    }
}
